package com.cheer.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cheer.dto.StandingBookReviewPageDTO;
import com.cheer.entity.Applicant;
import com.cheer.entity.StandingBook;
import com.cheer.entity.StandingBookReview;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface StandingBookReviewDao extends BaseMapper<StandingBookReview> {

    default List<StandingBookReview> listByOrgId(Long orgId) {
        return selectList(new QueryWrapper<StandingBookReview>()
                .eq("review_org_id", orgId));
    }

    default StandingBookReview getByAccountIdAndOrgId(Long accountId, Long orgId) {
        return selectOne(new QueryWrapper<StandingBookReview>()
                .eq("account_id", accountId)
                .eq("review_org_id", orgId)
                .last("limit 1"));
    }

    default void deleteByAccountIds(List<Long> accountIds) {
        delete(new QueryWrapper<StandingBookReview>()
                .in("account_id", accountIds));
    }

    List<StandingBookReviewPageDTO> listPage(@Param("reviewOrgId") Long reviewOrgId, @Param("orgPath") String orgPath,
                                             @Param("applicantName") String applicantName, @Param("contactPerson") String contactPerson,
                                             @Param("status") Integer status, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    default void updateByAccountIdAndReviewOrgId(StandingBookReview review, Long accountId, Long orgId) {
        update(review, new QueryWrapper<StandingBookReview>()
                .eq("account_id", accountId)
                .eq("review_org_id", orgId));
    }

    default void updateByIds(StandingBookReview review, List<Long> reviewIds) {
        update(review, new QueryWrapper<StandingBookReview>()
                .in("id", reviewIds));
    }
}
